package com.wl.service;

import com.wl.domain.User;
import com.wl.service.UserService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * feign的工厂类
 */
@Component
public class UserServiceFallbackFactory implements FallbackFactory<UserService> {
    @Override
    public UserService create(Throwable throwable) {
        //打印错误
        throwable.printStackTrace();
        //返回实例方法
        return new UserService() {
            @Override
            public User userById(Long id) {
                return new User(-1L, "触发熔断！", "用户服务不可用！");
            }
        };
    }
}
